package com.example.smartgreenhouse.service.impl;

import com.example.smartgreenhouse.entity.PumpHistoryStatus;
import com.example.smartgreenhouse.mapper.PumpStatusMapper;
import com.example.smartgreenhouse.service.PumpStatusService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
public class PumpStatusServiceImpl implements PumpStatusService {
    private final PumpStatusMapper pumpStatusMapper;

    @Override
    @Transactional
    public void insertPumpStatus(Long pumpId, Integer level, Boolean isAuto, Long greenhouseId) {
        PumpHistoryStatus status = new PumpHistoryStatus();
        status.setCurrentLevel(level);
        status.setIsAuto(isAuto);
        if (greenhouseId != null) {
            status.setGreenhouseId(greenhouseId);
        }
        if (pumpId != null) {
            status.setPumpId(pumpId);
        }

        pumpStatusMapper.insert(status);
    }

}